#!/bin/bash

# 设置脚本在发生错误时停止执行
set -e

# 输出日志函数
log() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - INFO - $1"
}

# 错误处理函数
error() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - ERROR - $1"
    exit 1
}

# 创建 tigera-operator.yaml 中的资源
log "Creating resources from tigera-operator.yaml..."
kubectl create -f  /root/tigera-operator.yaml
if [ $? -ne 0 ]; then
    error "Failed to create resources from tigera-operator.yaml."
fi
log "Resources created from tigera-operator.yaml successfully."

# 创建 custom-resources.yaml 中的资源
log "Creating resources from custom-resources.yaml..."
kubectl apply -f custom-resources.yaml
if [ $? -ne 0 ]; then
    error "Failed to create resources from custom-resources.yaml."
fi
log "Resources created from custom-resources.yaml successfully."

log "All tasks completed successfully."